home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Delete file(s) and dirs with TwinExpress from DOpus.
- *
- * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
- *
- * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
- * use GuiArc in stead of DOpus and a script, to deal with archives)
- *
- * Bug - The twin command "Delete" can be told to delete all files in all
- * subdirectories of a given subdir. BUT!! the command will not delete
- * all subdirectories of the given dir.
- * the command to do this is RMDIR (Remove Dir). BUT!! (there's that word
- * again) the command RMDIR can only remove a dir at a time.
- * Fix - Use the TREE command to build a list of all subdirectorys in the given
- * subdirectory and remove the one at a time. BUT!! if any spaces are in
- * the names of any of the SubDirectories, then the operation will fail
- * due to twin's problem with spaces in a file name !!
- * - this has not quite finished being written yet. will do it soon...
- */
-
- trace ?R
-
- DOpusPort = 'DOPUS.1'
-
- if ~show(l,"rexxsupport.library") then
- call addlib("rexxsupport.library",0,-30,0)
- if showlist('Ports', DOpusPort) = 0 then do
- say 'Directory Opus Arexx port not found. Aborting.'
- call CleanUp
- end
-
- address 'DOPUS.1'
- options results
-
- /* Get the current path and do file-deletion, depending on the */
- /* type of path (Twin-path or normal path) */
- 'Status 6 -1'
- GetEntry Result
- FilePath = Result
-
- if words(FilePath) > 1 then do
- Request "Spaces in File/Dir Names are not Allowed !!"
- exit
- end
-
- TopText "Deleting selected files..."
-
- if left(FilePath,1) ~= '*' then do
- /* DOpus Way */
- Delete
- Busy off
- exit
- end
- else do
- request "Are you sure you want to DELETE all selected entries ?"
- if result = 0 then do
- exit
- end
-
- busy on
- FilePath = SubStr(FilePath,2)
- GetSelectedAll
- SelectedEntries = result
- if SelectedEntries = 'RESULT' then do
- TopText "No files selected."
- call CleanUp
- end
-
- SD = EnterDir(FilePath)
-
- NumberOfEntries = words(SelectedEntries)
- do EntryNumber = 1 to NumberOfEntries
- Index = word(SelectedEntries, EntryNumber)
- SelectEntry Index 0 1
- GetEntry Index+1
- Entry = result
- File = strip(left(Entry,25))
-
- filename = file
- file = Quote(SD || file)
-
- if SubStr(Entry,26,9) = "Directory" then
- extra = 'SUBDIR'
- else
- extra = ''
-
- /* delete all files in all subdirs */
- address command 'echo >PPipe: delete' File extra
- /*
- if SubStr(Entry,26,9) = "Directory" then do
- address command 'echo >PPipe: y'
- address command 'echo >PPipe: echo deleted'
- address command 'echo >PPipe: help'
- call WaitForAFile
- call MakeATree
- call TreeToPaths
- call DeleteTree
- end
- */
- end
- end
-
- TopText "Ready"
- 'DisplayDir -1'
- address AREXX "Rexx:DOpus/Reread.rexx"
- call CleanUp
-
- exit
-
- /*---------------------------------------------------------------------------*/
-
- CleanUp: /* Remove any files and exit */
- Busy off
- exit
- return
-
- /*--------------------------------------------------------------------------*/
-
- Quote: procedure /* add quotes to string */
- parse arg string
- return '"'||string||'"'
-
- /*--------------------------------------------------------------------------*/
-
- GetWord: procedure /* get word from '|' separated string */
-
- parse arg number,words
-
- if(left(words,1) ~= '|') then
- words = '|'||words
- do i=1 to number
- idx = index(words, '|');
- words = substr(words, idx+1)
- end
- end = index(words, '|') - 1
- if words = "" then
- return ""
- ret_str = substr(words, 1, end)
- return ret_str
-
- /*--------------------------------------------------------------------------*/
-
- CountWords: procedure /* count words from '|' separated string */
-
- parse arg words
-
- count = 0
- idx = index(words, '|')
- do while idx ~= 0
- count = count + 1
- words = substr(words, idx+1)
- idx = index(words, '|')
- end
- return count
-
- /*--------------------------------------------------------------------------*/
-
- WaitForAFile:
-
- test = ''
- /* received is for a normal copy, sent is for a copy as */
- if open(PipeList, "QUEUE:Twin", 'R') then do
- do while (test ~= 'deleted')
- junk = readln(PipeList)
- test = right(junk , 7, '')
- end
- do while (test = 'deleted')
- junk = readln(PipeList)
- test = right(junk , 7, '')
- if test = 'deleted' then
- TopText junk
- end
- close(PipeList)
- end
-
- /*check for errors and show user the error*/
- fnd = find(junk,"Error:")
- if fnd > 0 then do
- Request right(junk,length(junk)-wordindex(junk,fnd)+1)
- busy off
- exit
- end
- return
-
- /*--------------------------------------------------------------------------*/
-
- MakeATree:
- TopText "Building a Tree of dir := " File
-
- open(DirTree, "T:DirTree", 'W')
-
- /* get a dir tree */
- address command 'echo >PPipe: tree ' File
- address command 'echo >PPipe: echo End-Of-Tree'
- address command 'echo >PPipe: help'
-
- test = ''
-
- /* received is for a normal copy, sent is for a copy as */
- if open(PipeList, "QUEUE:Twin", 'R') then do
- /* wait for the tree information to come in... */
- do while ((test ~= 'Tree') & (test ~= 'End-Of-Tree'))
- junk = readln(PipeList)
- test = left(junk , 4, '')
- end
- /* now read in the Tree information */
- do while (test ~= 'End-Of-Tree')
- junk = readln(PipeList)
- test = right(junk , 11, '')
- writeln(DirTree, junk)
- end
- close(PipeList)
- end
-
- close(DirTree)
- return
-
- /*--------------------------------------------------------------------------*/
-
- TreeToPaths:
- TopText "Converting DirTree " File " to paths for deletion..."
- /*
- trace ?r
- open(DirTree, "T:DirTree", 'R')
- open(TreePath, "T:TreePath", 'W')
-
- test = ''
- lastname = ''
- first = TRUE
- skip = FALSE
- gap = 6
- do while (test ~= 'End-Of-Tree')
- junk = readln(DirTree)
- test = right(junk , 11, '')
-
- if length(junk) > 3 then do
- name = right(junk,length(junk)-3)
- Done = False
- cnt = 1
-
- if first = False then
- /* do*/
- if left(name,gap-3) = space("",gap) then do
- lastname = deletelastname(lastname)
- if left(junk,3) = " " then do
- lastname = lastname || '/' || substr(junk,gap+1,length(junk)-gap)
- skip = True
- gap = gap + 3
- Done = True
- end
- gap = gap - 3
- end
- /* if Done = False then
- gap = gap + 3 */
- cnt = cnt + 1
- /* while Done = False */
-
- if first = TRUE then do
- lastname = name
- first = FALSE
- skip = TRUE
- end
-
- if (test ~= 'End-Of-Tree') then do
- if skip = FALSE then
- writeln(TreePath, Filename || '/' || lastname || name)
- else
- writeln(TreePath, Filename || '/' || lastname )
-
- skip = FALSE
- end
- end
- end
-
- close(DirTree )
- close(TreePath)
- */
- return
-
- DeleteLastName: procedure
- parse arg string
- bit = ''
- pos = length(string)
- count = 0
- do while((bit ~= ":") & (bit ~= "/") & (pos > 1))
- bit = substr(string, pos, 1)
- pos = pos - 1
- count = count + 1
- end
-
- if pos > 1 then
- rtn = left(string, length(string)-count)
- else
- rtn = string
-
- return rtn
-
- /*--------------------------------------------------------------------------*/
-
- DeleteTree:
-
- return
-
- /*--------------------------------------------------------------------------*/
-
- /* Cd into the sent Directory path
- - this is needed, as TWIN has a command parameter limi of 30 characters,
- and as we all know AmigaDos file & paths can easily go over this limit !!*/
-
- EnterDir: procedure
-
- parse arg Dev ':' Path
-
- /* get the 1st character to ddress the local or remote machine correctly */
- if left(Dev,1) = '~' then
- sbit = '~'
- else
- sbit = ''
-
- /* does the passed name have a DEVICE in it ? */
- if Dev ~= '' then
- address command 'echo >PPipe: cd' Dev || ':'
-
- do until (t2 = '')
- parse var Path t1 '/' t2
- path = t2
- if t1 ~= '' then
- address command 'echo >PPipe: cd' sbit || t1
- end
-
- return sbit
-